home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / handson / supercede / Knowodys / Projects / Primes / 1.0.2 / Primes.class (.txt) next >
Encoding:
Java Class File  |  1997-07-30  |  1.2 KB  |  38 lines

  1. import java.applet.Applet;
  2. import java.awt.Graphics;
  3.  
  4. public class Primes extends Applet {
  5.    int highest;
  6.  
  7.    public void init() {
  8.       new Integer(0);
  9.       this.highest = Integer.parseInt(((Applet)this).getParameter("highest"));
  10.    }
  11.  
  12.    public void paint(Graphics g) {
  13.       int row = 1;
  14.       int col = 1;
  15.       boolean[] primeArray = new boolean[this.highest + 1];
  16.  
  17.       for(int theNum = 1; theNum <= this.highest; ++theNum) {
  18.          primeArray[theNum] = true;
  19.  
  20.          for(int i = 2; i <= theNum / 2; ++i) {
  21.             if (theNum % i == 0) {
  22.                primeArray[theNum] = false;
  23.                break;
  24.             }
  25.          }
  26.  
  27.          if (primeArray[theNum]) {
  28.             g.drawString(" " + theNum, 30 * col++, 20 * row);
  29.             if (col == 10) {
  30.                col = 1;
  31.                ++row;
  32.             }
  33.          }
  34.       }
  35.  
  36.    }
  37. }
  38.